package com.baizhi.service;

import com.baizhi.annotations.RedisCache;
import com.baizhi.dao.CatalogMapper;
import com.baizhi.entity.Catalog;
import com.baizhi.entity.CatalogExample;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("catalogService")
@Transactional
public class CatalogServiceImpl implements CatalogService {

    @Resource
    private CatalogMapper catalogMapper;
    CatalogExample catalogExample = new CatalogExample();

    @Override
    @RedisCache
    public List<Catalog> findAll() {
        return catalogMapper.selectByExample(catalogExample);
    }

    @Override
    @RedisCache
    public Catalog findById(String id) {
        return catalogMapper.selectByPrimaryKey(id);
    }

    @Override
    public void save(Catalog catalog) {
        catalogMapper.insert(catalog);
    }

    @Override
    public void update(Catalog catalog) {
        catalogMapper.updateByPrimaryKeySelective(catalog);
    }

    @Override
    public void delete(String id) {
        catalogMapper.deleteByPrimaryKey(id);
    }
}
